package main

import (
	"fmt"
	"reflect"
)

type S struct {
	Name   string
	Age    int
	Weight int
}

func main() {
	var a, b, c, d interface{}
	a = 12
	b = "test"
	c = 1e12
	d = false
	//return typeof value
	fmt.Println(reflect.TypeOf(a)) //output int
	fmt.Println(reflect.TypeOf(b)) //output string
	fmt.Println(reflect.TypeOf(c)) //output float64
	fmt.Println(reflect.TypeOf(d)) //output bool
	a = []int{2, 3, 4}
	fmt.Println(reflect.TypeOf(a)) //output []int
	b = map[string]int{"age": 23}
	fmt.Println(reflect.TypeOf(b)) //output map[string]int
	c = &S{"chenwen", 23, 140}
	fmt.Println(reflect.TypeOf(c)) //output *main.S
	//e = 1
	//e = e.(int) + 1
	e := reflect.ValueOf(c)
	fmt.Println(e)        //output <*main.S Value>
	fmt.Println(e.Kind()) //output ptr
	f := e.Elem()
	fmt.Println(f) //<main.S Value>
	//fmt.Println(f.)
	for i := 0; i < f.NumField(); {
		fmt.Println(f.Field(i), f.Field(0).Type())
	}
	//fmt.Println() //chenwen

}
